package com.ocom.mqsimple.controller;

import com.ocom.common.constant.MqSimpleApiUrl;
import com.ocom.common.request.xfrecde.NotMealRecodeRequest;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.RandomUtil;
import com.ocom.common.utils.ResultUtil;
import com.ocom.mqsimple.business.consumedetail.ConsumeDetailExportProductService;
import com.ocom.mqsimple.business.notMeal.NotMealProductService;
import com.ocom.redis.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RestController
public class NotMealController {

    @Autowired
    NotMealProductService notMealProductService;

    @Resource
    RedisUtil redisUtil;

    @PostMapping(MqSimpleApiUrl.URL_notMeal)
    public Result notMealExport(@RequestBody NotMealRecodeRequest request){
        //防止超长mq <250
        String mqKey = "MqSimple:notMealExport:"+ RandomUtil.getRandomString(20);
        redisUtil.set(mqKey,request,86400l);
        log.info("未就餐导出开始,【{}】",request);
        notMealProductService.handle(mqKey);
        return ResultUtil.success();
    }
}
